<template>
	<view class="ticketDetails">
		<view class="container">
			<view class="list">
				<view class="item">
					<view>优惠券名称：</view>
					<view>{{ detailsData.giftName }}</view>
				</view>
				<view class="item">
					<view>券类型：</view>
					<view>
						{{ detailsData.giftType == 1 ? '代金券' : detailsData.giftType == 2 ? '折扣券' : detailsData.giftType == 3 ? '兑换券' : '' }}
					</view>
				</view>
				<!-- <view class="item" v-if="detailsData.templateType == 1">
                    <view>券面额：</view>
                    <view>{{ detailsData.couponVal }}</view>
                </view> -->
				<view class="item">
					<view>积分：</view>
					<view>
						{{ detailsData.needAmt==0?detailsData.needPoint:detailsData.needAmt}}积分
<!--						{{ detailsData.giftType == 1 ? '元' : detailsData.giftType == 2 ? '折' : detailsData.giftType == 3 ? '积分' : '' }}-->
					</view>
				</view>
				<!-- 				<view class="item">
					<view>生效时间:</view>
					<view>
						{{ detailsData.absStartTime ? detailsData.absStartTime : timeForMat(detailsData.afterDaysStart).t2 }}
					</view>
				</view>
				<view class="item">
					<view>过期时间:</view>
					<view>
						{{ detailsData.absEndTime ? detailsData.absEndTime : timeForMat(-detailsData.afterDaysEnd).t2 }}
					</view>
				</view>
				<view class="item">
					<view>核销站点:</view>
					<view>{{ detailsData.isAllStation == 1 ? '全部站点' : detailsData.allowStationName }}</view>
				</view>
				<view class="item">
					<view>消费油品:</view>
					<view>{{ detailsData.isAllPr == 1 ? '全部油品' : detailsData.allowPrName }}</view>
				</view>
				<view class="item">
					<view>最低金额:</view>
					<view>{{ detailsData.amtMin }} 元</view>
				</view>
				<view class="item">
					<view>最高金额:</view>
					<view>{{ detailsData.amtMax }} 元</view>
				</view>
				<view class="item">
					<view>使用时间:</view>
					<view>
						{{
                            detailsData.isAllDay == 1
                                ? '每天'
                                : detailsData.isAllDay == 2
                                ? dateConversion(detailsData.allowDay)
                                : detailsData.isAllDay == 3
                                ? dateWeek(detailsData.allowDay)
                                : ''
                        }}
					</view>
				</view>
				<view class="item">
					<view>使用时段:</view>
					<view>{{ detailsData.isAllTime == 1 ? '全时段' : detailsData.allowTime }}</view>
				</view> -->
				<view class="item">
					<view style=" line-height: 60rpx">兑换数量:</view>
					<lxc-count @handleCount="handleCountClick" :value="value" :min='min' :max='max' :delayed="100">
					</lxc-count>
				</view>
			</view>
		</view>

		<view class="btn" @click="conversion">确定兑换</view>


	</view>
</template>

<script>
	import LxcCount from '@/components/numbox.vue'
	import {
		giftExchange
	} from '@/api/index.js';
import { toast } from '../../../utils/common';
	export default {
		components: {
			LxcCount
		},
		data() {
			return {
				detailsData: {},
				value: 1,
				min: 1,
				max: 1000,
				memberId: '',
        stationId: '',
        stationName: '',
			};
		},
		onLoad(options) {
			this.memberId = JSON.parse(uni.getStorageSync('memberInfo')).memberId
			this.detailsData = JSON.parse(options.data);
      this.stationId = options.stationId
      this.stationName = options.stationName
		},
		methods: {
			thirtyDays(aa) {
				var date1 = new Date(),
					time1 = date1.getFullYear() + '-' + (date1.getMonth() + 1) + '-' + date1.getDate(); //time1表示当前时间
				var date2 = new Date(date1);
				date2.setDate(date1.getDate() + aa);
				var time2 = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate();
				return time2;
			},
			handleCountClick(val) {
				this.value = val
			},
			conversion() {
				uni.showLoading({
					title: '兑换中'
				});
				giftExchange({
						memberId: this.memberId,
            exchangeNum: this.value,
            giftId: this.detailsData.giftId,
            stationId: this.stationId,
            stationName: this.stationName
					})
					.then(res => {
						uni.hideLoading();
						if (res.data.code === 200) {
							toast('兑换成功，稍后发送到账户')
							setTimeout(() => {
								uni.navigateBack({
									delta: 1 // 返回上一级页面。
								});
							}, 1500);
						}
					})
					.catch(err => {
            uni.showToast({
              title: err,
              icon: 'none'
            })
						console.log(err);
					});
			}
		}
	};
</script>

<style lang="scss">
	.ticketDetails {
		padding: 20rpx 20rpx;

		// height: 100%;
		.container {
			border-radius: 8rpx;
			padding: 20rpx 15rpx;
			display: flex;
			background-color: white;

			.list {
				.item {
					display: flex;
					margin-bottom: 30rpx;

					view:nth-child(1) {
						width: 200rpx;
					}

					view:nth-child(2) {}
				}
			}
		}

		.btn {
			width: 250rpx;
			line-height: 80rpx;
			background-color: #006241;
			margin: auto;
			color: white;
			text-align: center;
			border-radius: 8rpx;
			margin-top: 50rpx;

			&:active {
				background-color: #006241;
				color: white;
			}
		}
	}
</style>